/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package entities.tools;
import entities.users.FormSigner;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
/**
 *
 * @author Marek
 */
@Entity
public class FilledForm implements Serializable {
    private static final long serialVersionUID = 1L;
    
    /**
     * 
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    /**
     * 
     */
    private boolean formWasFilled = false;
    
    /**
     * 
     */
    @ManyToOne
    private FormSigner formSigner;
        
    @OneToMany(cascade=(CascadeType.ALL),fetch = FetchType.EAGER, mappedBy = "filledForm")
    @OrderBy("orderNumber asc")
    private List<Answer> answers = new ArrayList<>();
    
    /**
     * 
     */
    private String linkHash;
    
    /**
     * 
     */
    @ManyToOne
    private Form form;
    
    /**
     * 
     */
    @Temporal(TemporalType.TIMESTAMP) 
    private Date whenCreated = new Date();
    
    /**
     * 
     */
    @Temporal(TemporalType.TIMESTAMP) 
    private Date whenFilled = new Date();
    
    /**
     * 
     * @return id 
     */
    public Long getId() {
        return id;
    }

    /**
     * 
     * @param id 
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * 
     * @return 
     */
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    /**
     * 
     * @param object
     * @return 
     */
    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof FilledForm)) {
            return false;
        }
        FilledForm other = (FilledForm) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    /**
     * 
     * @return the string representation of the FilledForm entity 
     */
    @Override
    public String toString() {
        return "entities.FilledForm[ id=" + id + " ]";
    }

    /**
     * @return the formSigner
     */
    public FormSigner getFormSigner() {
        return formSigner;
    }

    /**
     * @param formSigner the formSigner to set
     */
    public void setFormSigner(FormSigner formSigner) {
        this.formSigner = formSigner;
    }

    /**
     * @return the form
     */
    public Form getForm() {
        return form;
    }

    /**
     * @param form the form to set
     */
    public void setForm(Form form) {
        this.form = form;
    }

    /**
     * @return the answers
     */
    public List<Answer> getAnswers() {
        return answers;
    }

    /**
     * @param answers the answers to set
     */
    public void setAnswers(List<Answer> answers) {
        this.answers = answers;
    }

    /**
     * @return the formWasFilled
     */
    public boolean isFormWasFilled() {
        return formWasFilled;
    }

    /**
     * @param formWasFilled the formWasFilled to set
     */
    public void setFormWasFilled(boolean formWasFilled) {
        this.formWasFilled = formWasFilled;
    }

    /**
     * @return the whenFilled
     */
    public Date getWhenFilled() {
        return whenFilled;
    }

    /**
     * @param whenFilled the whenFilled to set
     */
    public void setWhenFilled(Date whenFilled) {
        this.whenFilled = whenFilled;
    }

    /**
     * @return the linkHash
     */
    public String getLinkHash() {
        return linkHash;
    }

    /**
     * @param linkHash the linkHash to set
     */
    public void setLinkHash(String linkHash) {
        this.linkHash = linkHash;
    }

    /**
     * @return the whenCreated
     */
    public Date getWhenCreated() {
        return whenCreated;
    }

    /**
     * @param whenCreated the whenCreated to set
     */
    public void setWhenCreated(Date whenCreated) {
        this.whenCreated = whenCreated;
    }
}
